/*
 *  SimpleRegexValidator.cs
 *  
 *  Validates the user input by regular expression.
 *  
 *  Copyright (c) 2009, Richard Bao Labs.
 *  
 *  The contents of this file are subject to the Mozilla Public License
 *  Version 1.1 (the "License"); you may not use this file except in
 *  compliance with the License. You may obtain a copy of the License at
 *  
 *  http://www.mozilla.org/MPL/
 *  
 *  Software distributed under the License is distributed on an "AS IS"
 *  basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
 *  the License for the specific language governing rights and limitations
 *  under the License.
 *  
 *  The Original Code is RichControlLibrary.
 *  
 *  The Initial Developer of the Original Code is Richard Bao Labs.
 *  All Rights Reserved.
 */

using System;
using System.Collections.Generic;
using System.Text;
using System.Text.RegularExpressions;

namespace RichControlLibrary
{
    /// <summary>
    /// Validates the user input by regular expression.
    /// </summary>
    public sealed class SimpleRegexValidator : RegexValidator
    {
        /// <summary>
        /// Initializes a new instance of the <see cref="SimpleRegexValidator"/> class by a specific
        /// <see cref="Regex"/>.
        /// </summary>
        /// <param name="validatingRegex">A <see cref="Regex"/> used to validate the user input.</param>
        public SimpleRegexValidator(Regex validatingRegex)
        {
            _validatingRegex = validatingRegex;
        }

        /// <summary>
        /// Initializes a new instance of the <see cref="SimpleRegexValidator"/> class by a specific
        /// regular expression string.
        /// </summary>
        /// <param name="validatingRegex">A regular expression string used to validate the user
        /// input.</param>
        public SimpleRegexValidator(string validatingRegex)
        {
            _validatingRegex = new Regex(validatingRegex);
        }

        private Regex _validatingRegex = null;
        /// <summary>
        /// Gets or set the <see cref="Regex"/> used to validate the user input.
        /// </summary>
        public Regex ValidatingRegex
        {
            get { return _validatingRegex; }
            set { _validatingRegex = value; }
        }

        /// <summary>
        /// Returns a <see cref="Regex"/> instance as the validating regular expression.
        /// </summary>
        /// <returns>A <see cref="Regex"/> used to validate the user input.</returns>
        protected override Regex GetValidatingRegex()
        {
            return _validatingRegex; 
        }
    }
}
